package com.lmf.dao.Impl;

import com.lmf.dao.StudentDao;
import com.lmf.domain.Student;
import com.lmf.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class StudentDaoImpl implements StudentDao {
    @Override
    public List<Student> selectStudents() {
        //获取SqlSession对象
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        String sqlId="com.lmf.dao.StudentDao.selectStudents";
        //执行sql语句
        List<Student> students = sqlSession.selectList(sqlId);
        //关闭sqlsession
        sqlSession.close();
        return students;
    }

    @Override
    public int insertStudent() {
        //获取SqlSession对象
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        String sqlId="com.lmf.dao.StudentDao.insertStudent";
        //执行sql语句
        int n= sqlSession.insert(sqlId,new Student(1008,"李八","ls168@qq.com",21));
        //关闭sqlsession
        sqlSession.close();
        return n;

    }
}
